package org.realteam.hibernate.test.model.em;

import java.util.HashMap;
import java.util.Map;

public class GenderEnum {
	
	private String gender;
	
	public static final GenderEnum MALE = new GenderEnum("Male");
	public static final GenderEnum FEMALE = new GenderEnum("FeMale");
	public static final GenderEnum OTHER = new GenderEnum("Other");
	
	private static final Map<Object, Object> INSTANCES = new HashMap<Object, Object>(3);
	
	static {
		INSTANCES.put(MALE.toString(), MALE);
		INSTANCES.put(FEMALE.toString(), FEMALE);
		INSTANCES.put(OTHER.toString(), OTHER);
	}
	
	private GenderEnum(String gender) {
		this.gender = gender;
	}
	
	public String toString() {
		return gender;
	}
	
	public Object readResolve() {
		return getInstance(gender);
	}
	
	public static GenderEnum getInstance(String gender) {
		return (GenderEnum)INSTANCES.get(gender);
	}
}
